import React from 'react'
import {Row,Col,message,Table,Modal,Button,Icon} from 'antd'
import styles from "./index.less";
import moment from 'moment'
const confirm = Modal.confirm
class New extends React.Component{
	constructor(props){
		super(props)
		this.state = {
			
		}
	}
	async pageChange(pagination) {
	    await this.props.onPageChange(pagination);
	    this.newPage = pagination.current;
	}
	showMenu(i){
		const { changeMenu } = this.props
		changeMenu(i)
	}
	edit = (value,i) =>{
		const {onDelete,showDetails} = this.props
		if(i == 1){
			showDetails(value.id)
		}
		if(i == 2){
			confirm({
		        title: '您确定要删除这条记录吗?',
		        onOk () {
		        		onDelete({id:value.id})
		        }
		      })
		}
		
	}
	render(){
		const {list,pagination1,loading} = this.props
		const list1 = [
			{
				title:1,
				time:1,
				name:1,
			}
		]
		const columns = [
			{
				title: "模板名称",
	        		dataIndex: "name",
	        		key: "name",
			},
			{
				title: "创建时间",
	        		dataIndex: "createTime",
	        		key: "createTime",
	        		render:(text,record) =>{
	        			return(
	        				<p>
	        					{moment(record.createTime).format("YYYY-MM-DD HH:mm:ss")}
	        				</p>
	        			)
	        		},
			},
			{
				title: "创建人",
	        		dataIndex: "createUserName",
	        		key: "createUserName",
			},
			{
				title: "操作",
	        		dataIndex: "operation",
	        		key: "operation",
	        		render:(text,record)=>{
	        			return(
	        				<div>
	        					<span onClick={this.edit.bind(null,record,1)} style={{marginRight:5}}><a>修改</a></span>
	        					<span onClick={this.edit.bind(null,record,2)} style={{marginRight:5}}><a>删除</a></span>
	        				</div>
	        			)
	        		}
			}
		]
		return(
			<div>
				<Button type="primary" onClick={this.showMenu.bind(this,1)}>
		        		<Icon type="left" />返回
		      	</Button>
				<div>
					<span style={{fontSize:16,fontWeight:600}}>电子资料模板列表</span>
				</div>
				<Button type="dashed" style={{width:"100%",margin:"20px 0",height:40}} onClick={this.showMenu.bind(this,3)}>
		        		<Icon type="plus" />新增
		      	</Button>
				<Table
			          columns={columns}
			          dataSource={list}
			          loading={loading}
			          onChange={this.pageChange.bind(this)}
			          pagination={pagination1}
			        />
			</div>
		)	
	}
}

export default New
